/*
* Tcp_Server.h
* Last edited: 27.08.2014
* Author: David Noack
*/

#ifndef TCP_SERVER_H_
#define TCP_SERVER_H_


#include "Com_Interface.h"
#include "MyThreadClass.h"

#define TCP_LOG "Log_tcp"


/**
\class Tcp_Server
\brief Implements a tcp-server for prngd.
*/
class Tcp_Server : public Com_Interface , MyThreadClass{

	public:
		/**Constructor*/
		Tcp_Server(Prngd_State state);

		/**Destructor*/
		~Tcp_Server()
		{
			if(prngd != NULL)
				delete prngd;
			if(new_socket != 0)
				close(new_socket);
			if(create_socket != 0)
				close(create_socket);

		};

	private:
		/** Unix socket for the tcp connection.*/
		int create_socket;
		/** Unix socket for the tcp communication.*/
		int new_socket;
		/** Var for the address length of the server.*/
		socklen_t addrlen;
		/** Struct for the inet address.*/
		struct sockaddr_in address;
		int temp_socket;

		/** See doc for My_ThreadClass.*/
		virtual void thread_listen(pthread_t parent_th);
		/** See doc for My_ThreadClass.*/
		virtual void thread_work();

};

#endif /* TCP_SERVER_H_ */

